define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'settle/log/index' + location.search,
                    add_url: 'settle/log/add',
                    edit_url: 'settle/log/edit',
                    del_url: 'settle/log/del',
                    multi_url: 'settle/log/multi',
                    import_url: 'settle/log/import',
                    table: 'settle_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'first_cate', title: __('一级分类'), searchList: Config.categoryList, formatter: Table.api.formatter.flag },
                        { field: 'two_cate', title: __('二级分类'), searchList: Config.categoryList, formatter: Table.api.formatter.flag },
                        { field: 'user.username', title: __('User.username'), operate: 'LIKE' },
                        { field: 'shareholder', title: __('联创&分红股东'),searchList: Config.groupList, formatter: Table.api.formatter.flag },
                        { field: 'investment', title: __('创投'), searchList: Config.groupList, formatter: Table.api.formatter.flag  },
                        { field: 'money', title: __('团队业绩'), operate:false },
                        { field: 'series_amount', title: __('系列业绩'), operate:false },
                        { field: 'address', title: __('区域'), operate: 'LIKE' },
                        { field: 'settletime', title: __('Settletime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        // { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
